package com.leetcode.LC;

public class LC1323 {
    public int maximum69Number(int num) {
        if (num == 6) {
            return 9;
        } else if (num == 9) {
            return num;
        }
        String s = String.valueOf(num);
        if (!s.contains("6")) {
            return num;
        }

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != '9') {
                builder.append('9' + s.substring(i + 1, s.length()));
                break;
            }
            builder.append(s.charAt(i));
        }
        return Integer.valueOf(builder.toString());

    }

    public static void main(String[] args) {
        System.out.println(new LC1323().maximum69Number(9999));
    }

}
